﻿namespace H2.Streams.Sections
{
    using H2.DataTypes;
    using H2.Streams;
    using System;
    using System.Text;

    public class UnicodeInfo
    {
        private MapStream Map;
        private int StartOffset;

        internal UnicodeInfo(MapStream map, int startOffset)
        {
            this.Map = map;
            this.StartOffset = startOffset;
        }

        public string[] ReadTable()
        {
            return new string(this.Map.ReadFixedLengthStringAt(this.StringTableOffset, (Length)this.StringTableSize, Encoding.UTF8, true).ToCharArray()).Split(new char[1], StringCount);
        }

        public int StringCount
        {
            get
            {
                return this.Map.ReadInt32At(this.StartOffset, true);
            }
            set
            {
                this.Map.WriteAt(this.StartOffset, value, true);
            }
        }

        public int StringIndexOffset
        {
            get
            {
                return this.Map.ReadInt32At(this.StartOffset + 8, true);
            }
            set
            {
                this.Map.WriteAt(this.StartOffset + 8, value, true);
            }
        }

        public int StringTableOffset
        {
            get
            {
                return this.Map.ReadInt32At(this.StartOffset + 12, true);
            }
            set
            {
                this.Map.WriteAt(this.StartOffset + 12, value, true);
            }
        }

        public int StringTableSize
        {
            get
            {
                return this.Map.ReadInt32At(this.StartOffset + 4, true);
            }
            set
            {
                this.Map.WriteAt(this.StartOffset + 4, value, true);
            }
        }
    }
}

